﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Furion.RemoteRequest;

using OOS.Application.User.Services.Dtos;
using OOS.Application.User.Services.Interfaces;
using OOS.Application.User.Services.Vos;
using OOS.Core.RelyOn;
using OOS.Core.User;

namespace OOS.Application.User
{
    /// <summary>
    /// 用户管理
    /// </summary>
    [Route("[Controller]")]
    public class UserBasicAppService:IDynamicApiController
    {
        private readonly IUserBasicService _userBasicService;

        public UserBasicAppService(IUserBasicService userBasicService)
        {
            _userBasicService = userBasicService;
        }

        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="loginVo"></param>
        /// <param name="flag"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public LoginDto Login(LoginVo loginVo,Boolean flag)
        {
            return _userBasicService.Login(loginVo,flag);
        }

        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="loginVo"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public LoginDto Register(LoginVo loginVo)
        {
            return _userBasicService.Register(loginVo);
        }

        /// <summary>
        /// 新增用户
        /// </summary>
        /// <param name="userBasic"></param>
        /// <returns></returns>
        [HttpPost]
        public bool AddUserBasic(UserBasic userBasic)
        {
            return _userBasicService.InsertUserBasic(userBasic);
        }

        /// <summary>
        /// 根据Id查询用户详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        public UserBasicDto GetUserBasic(int Id)
        {
            return _userBasicService.SelectUserById(Id);
        }

        /// <summary>
        /// 修改用户信息
        /// </summary>
        /// <param name="userBasic"></param>
        /// <returns></returns>
        [HttpPut]
        public bool UpdateUserBasic(UserBasic userBasic)
        {
            return _userBasicService.UpdateUserBasicById(userBasic);
        }

        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="userBasic"></param>
        /// <returns></returns>
        [HttpPut]
        public bool UpdatePassword(UserBasic userBasic)
        {
            return _userBasicService.UpdateUserBasicById(userBasic);
        }

        /// <summary>
        /// 按条件(用户名模糊查询，登录账号模糊查询，用户状态精确查询,用户类型精确查询)分页查询
        /// </summary>
        /// <param name="searchUserVo"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public PageResponseDto<List<UserBasicDto>> GetUserList([FromQuery]SearchUserVo searchUserVo,int pageIndex, int pageSize)
        {
            UserBasic userBasic = searchUserVo.Adapt<UserBasic>();
            return _userBasicService.SelectByContitionsByPage(userBasic, pageIndex, pageSize);
        }

        /// <summary>
        /// 根据id删除用户
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public bool DeleteUserBasic(int id)
        {
            return _userBasicService.DeleteUserBasicById(id);
        }
    }
}
